<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>待审核列表</title>
    <%@ include file="/view/common/tags.jsp"%>
    <script type="text/javascript" src="${sysManagerV1}/js/My97DatePicker/WdatePicker.js"> </script>
</head>
<body>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box">
                <div class="box-body">
                    <div class="panel panel-default">
                        <div class="panel-body" style="padding-bottom:5px;">
                            <form class="form-horizontal" action="" method="post" id="dataForm">
                                <input type="hidden" id="token" name="token" value=""/>
                                <div class="searchMenu" >

                                </div>
                            </form>
                        </div>
                    </div>
                    <table class="table table-hover table-condensed table-bordered table-striped" id="dataTable" >
                        <thead>
                        <tr>
                            <th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false">序号</th>
                            <th data-field="gameName" data-align="center" data-sortable="false">游戏信息</th>
                            <th data-field="areaName" data-align="center" data-sortable="false">游戏区</th>
                            <th data-field="serverName" data-align="center" data-sortable="false">游戏服</th>
                            <th data-field="goodsCode" data-align="center" data-sortable="false">商品编号</th>
                            <th data-field="goodsTitle" data-align="center" data-sortable="false">商品名称</th>
                            <th data-field="tradeName" data-align="center" data-sortable="true">交易类型</th>
                            <th data-field="goodsSmallName" data-align="center" data-sortable="true">商品小类</th>

                            <th data-field="goodsDes" data-align="center" data-sortable="false">商品描述</th>
                            <th data-field="remainNum" data-align="center" data-formatter="imgFormatter" data-sortable="false">商品图片</th>
                            <th data-field="goodsPublishTime" data-align="center" data-formatter="timeFormatter_point" data-sortable="true">发布时间</th>
                            <th data-field="deleteButton" data-align="center"  data-formatter="buttonFormatter" data-sortable="false">操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>
<%@ include file="/view/common/footer.jsp"%>
</body>
<script>
    // 提示信息
    var msgg='<%=request.getAttribute("msg")%>';
    if (msgg && msgg!=null && msgg!='null') {
        layer.msg(msgg);
    }
    var tableIndex = 0; // 添加修改的弹出框的ID

    // 加载table 数据
    $(function(){
        $("#token").val(sessionStorage.getItem("token"));
        console.log("token = " + sessionStorage.getItem("token"));
        $("#dataTable").bootstrapTable({
            url: "${tradeV1}/tradeGoodsAudit/waitForAudit.json",
            method:"get",
            pagination:true,
            sidePagination:"server",
            queryParams: function(params) {
                return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));
            }
        });
    })

    //查询
    function findData(){
        $("#dataTable").bootstrapTable("refresh",{} );
    }

    /*bootstrap table点击行事件*/
    $(function(){
        $("body").on("click","table>tbody>tr",function(){
            $(this).css("background","#e1ecf1").siblings().css("background","");
        });
    })

    // 商品状态
    function goodsStateFormatter(value, row) {
        var html = "";
        if (row.goodsState == 10) {
            html = "<span class='text-success'>上架中</span>";
        }else if (row.goodsState == 20){
            html = "<span class='text-warning'>待审核</span>";
        }else if (row.goodsState == 30){
            html = "<span class='text-warning'>待处理问题商品</span>";
        }else if (row.goodsState == 40){
            html = "<span class='text-warning'>下架中</span>";
        }else if (row.goodsState == 50){
            html = "<span class='text-warning'>已删除</span>";
        }else if (row.goodsState == 60){
            html = "<span class='text-warning'>已完成</span>";
        }else{
            html = "<span class='text-warning'>未知状态</span>";
        }
        return html;
    }

    // 操作
    function buttonFormatter(value, row, index) {
        var button = "<button id='_updateYes' type='button' onclick='_updateYes("+row.rowId+",1);'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>审核通过</button>";
        button += "<button id='_updateNo' type='button' onclick='_updateNo("+row.rowId+",2);'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>审核不通过</button>";
        return button;
    }

    // 查看图片
    function imgFormatter(value, row, index) {
        var button;
        if(row.imageFlag == 1){
            button = "<button id='btn_edit' type='button' onclick='viewImg("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon'>查看图片</span></button>";
        }else{
            button = "<button id='btn_edit' type='button' class='btn btn-default btn-sm'><span class='glyphicon'>暂无图片</span></button>";
        }
        return button;
    }

    // 审核通过
    function _updateYes(rowId, updateFlag){
        layer.confirm('确认审核通过吗？', {
                btn: ['确认', '取消']
            },
            function(){
                $.post("${tradeV1}/tradeGoodsAudit/auditGoods?rowId="+rowId+"&updateFlag="+updateFlag+"&token="+$("#token").val(),null,function(data){
                    if (data == 1) {
                        layer.alert("操作成功", {icon: 1});
                        findData();
                    } else {
                        layer.alert("操作失败", {icon: 5});
                    }
                });
            },
            function(){
                return;
            });
    }

    // 审核不通过
    function _updateNo(rowId, updateFlag){
        tableIndex = layer.open({
            type: 2,
            title: "选择审核失败原因",
            closeBtn: 1,
            shadeClose: false,
            area: ['350px', '250px'],
            content: "${sysManagerV1}/tradeGoodsAudit/toChooseReason?rowId=" + rowId + "&updateFlag="+updateFlag,
            btn: ["确 认","关 闭"],
            yes: function(index, layero){
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.add();
            }
        });
    }

    // 查看图片
    function viewImg(rowId){
        tableIndex = layer.open({
            type: 2,
            title: "商品图片",
            closeBtn: 1,
            shadeClose: false,
            area: ['550px', '480px'],
            content: "${sysManagerV1}/tradeGoodsAudit/toViewImg?rowId=" + rowId ,
            btn: ["确 认"]
        });
    }

</script>
</html>